package leetcode.每日一题;

import org.junit.Test;

import java.util.Comparator;
import java.util.Map;
import java.util.PriorityQueue;

/**
 * @author ：zsy
 * @date ：Created 2022/10/24 9:48 AM
 * @description：https://leetcode.cn/problems/partition-array-into-disjoint-intervals/
 */
public class 分割数组 {
    @Test
    public void test() {
        System.out.println(new Solution().partitionDisjoint(new int[]{5,0,3,8,6}));
    }

    class Solution {
        public int partitionDisjoint(int[] nums) {
            int len = nums.length;
            PriorityQueue<Integer> queue = new PriorityQueue<>();
            for (int num : nums) {
                queue.offer(num);
            }
            int l = 0;
            int max = nums[l];
            while (l < len && !queue.isEmpty()) {
                int num = nums[l];
                max = Math.max(max, num);
                queue.remove(num);
                if (max < queue.poll()) {
                    break;
                }
                l++;
            }
            return l - 1;
        }
    }
}
